$(function() {
	top.hangge();
	// 下拉框
	if (!ace.vars['touch']) {
		$('.chosen-select').chosen({
			allow_single_deselect : true
		});
		$(window).off('resize.chosen').on('resize.chosen', function() {
			$('.chosen-select').each(function() {
				var $this = $(this);
				$this.next().css({
					'width' : $this.parent().width()
				});
			});
		}).trigger('resize.chosen');
		$(document).on('settings.ace.chosen', function(e, event_name, event_val) {
			if (event_name != 'sidebar_collapsed')
				return;
			$('.chosen-select').each(function() {
				var $this = $(this);
				$this.next().css({
					'width' : $this.parent().width()
				});
			});
		});
		$('#chosen-multiple-style .btn').on('click', function(e) {
			var target = $(this).find('input[type=radio]');
			var which = parseInt(target.val());
			if (which == 2)
				$('#form-field-select-4').addClass('tag-input-style');
			else
				$('#form-field-select-4').removeClass('tag-input-style');
		});
	}

	// 复选框全选控制
	var active_class = 'active';
	$('#simple-table > thead > tr > th input[type=checkbox]').eq(0).on('click', function() {
		var th_checked = this.checked;// checkbox inside "TH" table header
		$(this).closest('table').find('tbody > tr').each(function() {
			var row = this;
			if (th_checked)
				$(row).addClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', true);
			else
				$(row).removeClass(active_class).find('input[type=checkbox]').eq(0).prop('checked', false);
		});
	});
	//日期框
	$('.date-picker').datepicker({
		autoclose : true,
		todayHighlight : true,
		clearBtn : true
	});
	//ajax加载数据，弹出Loading
	$.ajaxSetup({
		beforeSend : function(evt, request, settings) {
			if (request && request.data && request.data.indexOf && request.data.indexOf("hideLoading=true") != -1) {
			} else {
				top.jzts();
			}
		},
		complete : function() {
			top.hangge();
		}
	});

})
